<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>学生表修改删除</title>
</head>
<body>
    <h1>修改删除学生表单：</h1>
    <div>
        <label for="name"></label>
        <input type="text" id="name" placeholder="名字" value="{{ student.name }}">
    </div>
    <div>
        <label for="sex"></label>
        <select id="sex">
            <option value="0">男</option>
            <option value="1">女</option>
            <option value="2">未知</option>
        </select>
    </div>
    <div>
        <label for="age"></label>
        <input type="text" id="age" placeholder="年龄" value="{{ student.age }}">
    </div>
    <div>
        <label for="no"></label>
        <input type="text" id="no" placeholder="学号" value="{{ student.no }}">
    </div>
    <div>
        <label for="class_name"></label>
        <select id="class_name">
            <option value="c1">c1</option>
            <option value="c2">c2</option>
        </select>
    </div>
    <div>
        <button id="submili_xg">提交修改</button>
    </div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function() {
    var sex = '{{ student.sex }}';
    $('#sex').val(sex);
    var class_name = '{{ student.class_name }}';
    $('#class_name').val(class_name);
    var id = '{{ student.id }}';

    $('#submili_xg').click(function() {
        var name = $.trim($("#name").val());
        var sex = $("#sex").val();
        var age = $.trim($("#age").val());
        var no = $.trim($("#no").val());
        var class_name = $("#class_name").val();
        if (name == '') {
            alert("请填写名字！");
        } 
        else if(age == "") {
            alert('请填写年龄！');
        }
        else if(no == "") {
            alert('请填写学号！');
        }
        else {
            $.post("/api/student_updata",{
                'id':id,
                'name':name,
                'sex':sex,
                'age':age,
                'no':no,
                'class_name': class_name
            },function(res) {
                if(res.code == 1){
                    window.location.href = '/students';
                }
            });
        }
    });
});
</script>
</html>